#include <iostream>
#include <string>
#include <deque>
#include "word_counter.h"
#include "../Fakultet/hr_time.h"
#include "unordered_list.h"
#include "statistics.h"

using namespace std;

namespace U31
{
	bool palindrome(string s)
	{
		deque<char> deq;
		for (int i = 0; i < s.size(); i++)
		{
			deq.push_front(s[i]);
		}
		bool palindrome = true;
		while (!deq.empty())
		{
			char cf = deq.front();
			char cb = deq.back();
			deq.pop_front();
			if (!deq.empty())
				deq.pop_back();
			if (cf != cb)
			{
				palindrome = false;
				break;
			}
		}
		return palindrome;
	}

	bool rekpalindrome(string s, int start, int end)
	{
		if (start >= end)
			return true;
		else
			return s[start] == s[end] && rekpalindrome(s, start + 1, end - 1);
	}
}

void main3_1()
{
	cout << U31::palindrome("kalle") << U31::palindrome("naturrutan") << U31::rekpalindrome("kalle", 0, 4) << U31::rekpalindrome("naturrutan", 0, 9) << endl;
}

void main3_2()
{
	U32::statistics s;
	s.read_salaries("salary.txt");
	cout << s.calculate_mean() << endl;
	cout << s.calculate_median() << endl;
}

void main3_3()
{
	U33::word_counter counter;
	if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) == 0)
	{
		std::cout << "Error: SetPriorityClass: " << GetLastError() << endl;
	}
	if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) == 0)
	{
		std::cout << "Error: SetThreadPriority" << endl;
	}

	CStopWatch w;
	w.startTimer();
	counter.print_max("nils_holgersson.txt");
	w.stopTimer();
	std::cout.precision(8);
	//std::cout.setf(ios::fixed);
	cout << 1e6*w.getElapsedTime() << endl;
}

void main4_1()
{
	using namespace U41;
	unordered_list ul(4);
	ul.add("a");
	ul.add("b");
	ul.add("c");
	ul.add("d");
	ul.delete_header_node();
	ul.delete_header_node();
	ul.add("e");
	ul.add("f");
	ul.add("g");
	ul.clear();
}

int main()
{
	//main3_1();
	main3_2();
	//main3_3();
	//main4_1();

	system("pause");
	return 0;
}